package com.itheima05;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class ServerDemo {
    public static void main(String[] args) throws IOException {
        // 创建服务端 socket
        ServerSocket s = new ServerSocket(10000);

        // 监听客户端链接
        Socket socket = s.accept();

        // 获取输入流，接收数据
        InputStream is = socket.getInputStream();
        byte[] bytes = new byte[1024];
        int len = is.read(bytes);
        System.out.println("服务器：" + new String(bytes, 0, len));

        // 给出反馈
        OutputStream os = socket.getOutputStream();
        os.write("数据已经收到".getBytes());

        // 释放资源
//        socket.close();
        s.close();
    }
}
